package com.huawei.hwid.api.common;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.cloudservice.CloudRequestHandler;
import com.huawei.cloudservice.LoginHandler;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.d.b;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.d.g;
import com.huawei.hwid.core.datatype.HwAccount;
import com.huawei.hwid.core.helper.handler.ErrorStatus;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;

public class o {
    private static LoginHandler a;
    private static boolean b = true;
    private static String c;

    public static LoginHandler a() {
        return a;
    }

    public static synchronized void a(LoginHandler loginHandler) {
        synchronized (o.class) {
            a = loginHandler;
            e.b("SDKUtil", "setHandler, mHandler is ", true);
        }
    }

    public static synchronized void a(Context context, String str) {
        synchronized (o.class) {
            c = str;
            g.a(context, "curName", c);
            e.b("SDKUtil", "setCurrentLoginUserName", true);
        }
    }

    public static String a(Context context) {
        if (TextUtils.isEmpty(c)) {
            a(context, g.b(context, "curName"));
        }
        e.b("SDKUtil", "getCurrentLoginUserName", true);
        return c;
    }

    public static boolean b(Context context) {
        if (context != null) {
            return b.j(context);
        }
        e.b("SDKUtil", "context is null", true);
        return false;
    }

    public static boolean a(Context context, int i) {
        if (context == null) {
            e.b("SDKUtil", "context is null", true);
            return false;
        } else if (d(context) < i) {
            return true;
        } else {
            return false;
        }
    }

    static boolean a(Context context, CloudRequestHandler cloudRequestHandler) {
        if (cloudRequestHandler == null) {
            e.b("SDKUtil", "requestHandler is null", true);
            return false;
        } else if (context != null) {
            return true;
        } else {
            e.b("SDKUtil", "context is null", true);
            cloudRequestHandler.onError(new ErrorStatus(12, "context is null"));
            return false;
        }
    }

    static HwAccount a(Context context, Bundle bundle) {
        HwAccount hwAccount = new HwAccount();
        if (bundle != null) {
            String string = bundle.getString("accountName");
            String string2 = bundle.getString("userId");
            String string3 = bundle.getString("deviceId");
            String string4 = bundle.getString("subDeviceId");
            String string5 = bundle.getString("deviceType");
            int i = bundle.getInt("siteId");
            String string6 = bundle.getString("serviceToken");
            String string7 = bundle.getString("accountType");
            String string8 = bundle.getString("loginUserName");
            String string9 = bundle.getString("countryIsoCode");
            String string10 = bundle.getString("uuid");
            String string11 = bundle.getString(HwAccountConstants.EXTRA_AS_SERVER_DOMAIN);
            String string12 = bundle.getString(HwAccountConstants.EXTRA_CAS_SERVER_DOMAIN);
            hwAccount.b(string);
            hwAccount.h(string3);
            hwAccount.i(string4);
            hwAccount.j(string5);
            hwAccount.a(i);
            hwAccount.f(string6);
            hwAccount.d(string2);
            hwAccount.c(b.c(context));
            hwAccount.g(string7);
            hwAccount.k(string8);
            hwAccount.a(string9);
            hwAccount.p(string10);
            hwAccount.n(string11);
            hwAccount.o(string12);
        }
        return hwAccount;
    }

    public static String c(Context context) {
        try {
            String str = context.getPackageManager().getPackageInfo("com.huawei.hwid", 0).versionName;
            e.b("SDKUtil", "versionName ", true);
            return str;
        } catch (NameNotFoundException e) {
            e.d("SDKUtil", "NameNotFoundException getVersionTag error = ", true);
        } catch (Exception e2) {
            e.d("SDKUtil", "Exception getVersionTag error", true);
        }
        return "";
    }

    public static int d(Context context) {
        try {
            int i = context.getPackageManager().getPackageInfo("com.huawei.hwid", 0).versionCode;
            e.b("SDKUtil", "versionCode " + i, true);
            return i;
        } catch (NameNotFoundException e) {
            e.d("SDKUtil", "NameNotFoundException error", true);
        } catch (Exception e2) {
            e.d("SDKUtil", "Exception error", true);
        }
        return 0;
    }

    public static boolean a(Context context, Intent intent) {
        if (intent == null || context.getPackageManager().queryIntentActivities(intent, WXMediaMessage.THUMB_LENGTH_LIMIT).size() <= 0) {
            return false;
        }
        return true;
    }
}
